package com.jh.controller;

import com.jh.dto.OderPageQueryDTO;
import com.jh.dto.SettlementDataDTO;
import com.jh.result.ListResult;
import com.jh.result.PageResult;
import com.jh.result.Result;
import com.jh.service.SettlementService;
import com.jh.vo.OderPageQueryVO;
import com.jh.vo.OrderDetailDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/settlement")
@Api(tags = "订单相关接口")
@Slf4j
public class SettlementController {

    @Autowired
    private SettlementService settlementService;

    @PostMapping("/submit")
    @ApiOperation("工作台提交订单")
    public Result submitSettlement(@RequestBody SettlementDataDTO settlementDataDTO) {
        try {
            log.info("工作台提交订单：,settlementDataDTO{}", settlementDataDTO);
            settlementService.submitSettlement(settlementDataDTO);
            return Result.success();
        } catch (Exception e) {
            throw new RuntimeException("订单提交失败",e);
        }
    }

    @GetMapping("/getOrderData")
    @ApiOperation("订单分页查询")
    public Result<PageResult> page(OderPageQueryDTO oderPageQueryDTO) {
        try {
            log.info("订单分页查询,oderPageQueryDTO:{}",oderPageQueryDTO);
            PageResult pageResult = settlementService.page(oderPageQueryDTO);
            return Result.success(pageResult);
        } catch (Exception e) {
            throw new RuntimeException("订单分页查询失败", e);
        }
    }

    @GetMapping("/getOrderDetails")
    @ApiOperation("根据id查询订单详情")
    public Result getOrderDetails(@RequestParam(name = "orderId", required = true) Long orderId){
        log.info("根据id查询订单详情,id：{}",orderId);
        List<OrderDetailDTO> listResult =settlementService.getOrderDetails(orderId);
        return Result.success(listResult);
    }

    @GetMapping("/deleteOrder")
    @ApiOperation("根据id删除订单")
    public Result deleteOrder(@RequestParam(name = "orderId", required = true) Long orderId){
        try {
            log.info("根据id删除订单,id：{}", orderId);
            settlementService.deleteOrder(orderId);
            return Result.success();
        } catch (Exception e) {
            throw new RuntimeException("订单删除失败", e);
        }
    }
}
